package com.sky.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
@Slf4j
public class RedisConfiguration {

    /**
     *
     * @param redisConnectionFactory 负责创建redis的连接（里面就含有我们配置的redis的信息）
     * @return
     *
     * RedisTemplate 操作redis的核心对象 后期都是 用他来操作redis
     */
    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory){
        RedisTemplate redisTemplate = new RedisTemplate();

        //设置连接工程对象
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        //设置key的序列化
        redisTemplate.setKeySerializer(new StringRedisSerializer());

        return redisTemplate;
    }
}
